<template>
	<view class="main" :style="{paddingBottom:(getSafeBottom )+'px'}">
		<navbar title="招聘活动"></navbar>
		<view class="content" :style="{paddingTop:(getStateHeight + getNavbar  ) + 'px'}">
			<view class="item-box">
				<view class="item" v-for="(item,index) in dataList" :key="item.id" @click="toDetail(item)">
					<view class="item-picdir">
						<image :src="baseImage + item.picdir" mode="" v-if="item.picdir"></image>
						<image :src="imgUrl + 'recruitIcon.jpg'" mode="" v-else></image>
					</view>
					<view class="item-data">
						<view class="item-title">
							{{item.title}}
						</view>
						<view class="item-line">
							<view class="item-line-icon">
								<image :src="imgUrl + 'clockIcon.png'" mode="widthFix"></image>
							</view>
							<view class="item-line-label">
								{{item.timeStart? item.timeStart.split(" ")[0]:""}} - {{item.timeEnd? item.timeEnd.split(" ")[0]:""}}
							</view>
						</view>
						<view class="item-line">
							<view class="item-line-icon">
								<image :src="imgUrl + 'addrIcon.png'" mode="widthFix"></image>
							</view>
							<view class="item-line-label">
								{{item.addr}}
							</view>
						</view>
						<view class="item-button" :class="[getStatus(item.timeStart,item.timeEnd).className]">
							{{getStatus(item.timeStart,item.timeEnd).title}}
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="main-bj">
			
		</view>
	</view>
</template>

<script>
	import dayjs from "dayjs"
	import {
		mapGetters,
		mapState
	} from 'vuex';
	import Navbar from '@/components/Navbar.vue'
	import {getServeList} from "@/core/web-api/qiuzhiduan.js"
	export default{
		data(){
			return {
				dataList:[],
				page:{
					current:1,
					limit:10,
				}
			}
		},
		methods:{
			toDetail(item){
				uni.navigateTo({
					url:"/pages/web/service/share/detail?cataname=zhaopin&id=" + item.id
				})
			},
			/**
			 * 加载数据
			 */
			getList() {
				getServeList({
					...this.page,
					cataName:"招聘活动"
				}).then(res => {
					if (res.code == 20000) {
						const {
							total,
							list
						} = res.data;
						if (this.page.current == 1) {
							this.dataList = list;
						} else {
							this.dataList.push(...list);
						}
						this.total = total;
					}
				})
			},
			
			/**
			 * 分页加载
			 */
			pageData() {
				if (this.total == this.dataList.length) return;
				this.page.current++;
				this.getList()
			},
		},
		onReachBottom() {
			this.pageData();
		},
		components:{
			Navbar
		},
		computed: {
			...mapGetters(['getNavbar', 'getStateHeight', 'getSafeBottom']),
			...mapState(['baseImage','imgUrl']),
			getStatus(){
				return function(start,end){
					let obj = {
						className:"",
						title:""
					}
					if(!start || !end) return obj;
					let diffStart = dayjs().diff(start);
					let diffEnd = dayjs().diff(end);
					if(diffStart > 0 && diffEnd < 0){
						obj.className = "success";
						obj.title = "查看详情"
					}else if(diffStart < 0){
						obj.className = "";
						obj.title = "未开始"
					}else if(diffEnd > 0){
						obj.className = "";
						obj.title = "已结束"
					}
					return obj
				}
			}
		},
		created() {
			this.getList()
		}
	}
</script>

<style scoped lang="less">
	.main {
		width: 100%;
		padding: 0 30upx;
		box-sizing: border-box;
	
		&-bj {
			width: 100%;
			height: 50vh;
			position: fixed;
			left: 0;
			top: 0;
			z-index: -1;
			background: linear-gradient(to bottom, #bdccfb, #f5f5f5);
		}
	}
	.content{
		margin-top: 30upx;
	}
	.item{
		width: 100%;
		padding:30upx 20upx;
		box-sizing: border-box;
		margin-bottom: 40upx;
		background-color: #fff;
		border-radius: 8upx;
		display: flex;
		&-picdir{
			min-width: 200upx;
			height: 200upx;
			border-radius: 20upx;
			image{
				width: 100%;
				height: 100%;
				border-radius: 20upx;
			}
		}
		&:last-child{
			margin-bottom: 0;
		}
		&-data{
			flex:1;
			margin-left: 30upx;
			display: flex;
			flex-direction: column;
			justify-content: space-between;
			min-width: 0upx;
		}
		&-title{
			font-size: 32upx;
			color: #000000;
			font-weight: bold;
			white-space: nowrap;
			/* 不换行 */
			overflow: hidden;
			/* 隐藏超出部分 */
			text-overflow: ellipsis;
			/* 使用省略号表示超出部分 */
		}
		&-line{
			display: flex;
			align-items: center;
			&-icon{
				width: 20upx;
				margin-right: 10upx;
				display: flex;
				align-items: center;
				image{
					width: 20upx;
				}
			}
			&-label{
				font-size: 25upx;
				color: #666666;
				white-space: nowrap;
				/* 不换行 */
				overflow: hidden;
				/* 隐藏超出部分 */
				text-overflow: ellipsis;
				/* 使用省略号表示超出部分 */
			}
		}
		&-button{
			font-size: 24upx;
			width: 120upx;
			height: 45upx;
			text-align: center;
			line-height: 45upx;
			border-radius: 10upx;
			background-color: #f6f7f9;
			color: #454545;
			&.success{
				color: #fff;
				background: linear-gradient(to bottom, #5472fd, #6ca5fd);
			}
		}
	}
</style>